package com.peanut.baby.mvp.calendar;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.ListView;

import androidx.annotation.Nullable;

import com.peanut.baby.AppConfig;
import com.peanut.baby.R;
import com.peanut.baby.model.Baidai;
import com.peanut.baby.mvp.BaseMvpActivity;
import com.peanut.devlibrary.widget.TitleLayout;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by anonymouslystudio on 2017/8/24.
 */

public class BaidaiOptionsActivity extends BaseMvpActivity implements TitleLayout.OnTitleClickListener{
    @BindView(R.id.title)
    TitleLayout title;
    @BindView(R.id.listview)
    ListView listview;

    private BaidaiOptionsListAdapter adapter;

    private String old = "";

    private List<Baidai> data;

    public static void startForResult(Activity act,String old) {
        act.startActivityForResult(new Intent(act, BaidaiOptionsActivity.class).putExtra("old",old), AppConfig.RequestResult.REQUEST_CODE_BAIDAI);
    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_baidai_options);
        ButterKnife.bind(this);
        old = getIntent().getStringExtra("old");
        init();
    }

    private void init(){
        title.setTitle("宫颈粘液");
        title.setOnTitleClickedListener(this);
        title.setTitleRightText("确定");
        title.setTitleRightVisibility(true);
        title.setTitleRightTextColor(getResources().getColor(R.color.colorPrimary));


        data = getBaidaiList();
        initOldSelected();
        adapter = new BaidaiOptionsListAdapter(this,data);
        listview.setAdapter(adapter);

    }

    @Override
    public void onTitleBackClicked() {
        finish();
    }

    @Override
    public void onTitleRightClicked() {
        Baidai selected = adapter.getCheckedItem();

        if(selected == null){
            showToast("请选择一项内容");
            return;
        }
        Intent intent = new Intent();
        intent.putExtra(Intent.EXTRA_RETURN_RESULT,selected.title);
        setResult(RESULT_OK,intent);
        finish();
    }

    @Override
    public void onTitleClicked() {

    }

    private List<Baidai> getBaidaiList(){
        List<Baidai> data = new ArrayList<>();
        data.add(new Baidai("无","清空内容",false));
        data.add(new Baidai("只有经血","月经期，坐等排卵",false));
        data.add(new Baidai("无经血，无拉丝","无粘液，安全期",false));
        data.add(new Baidai("拉丝<2.5cm","少量浑浊粘稠粘液，排卵期在招手",false));
        data.add(new Baidai("拉丝2.5cm~4cm","少量浑浊粘液,已经感觉到它的呼吸了",false));
        data.add(new Baidai("拉丝4cm~10cm","较多量、较透明、较稀薄粘液，可能就在这两天",false));
        data.add(new Baidai("拉丝>=10cm","多量、透明、很稀薄粘液，24小时内可能排卵",false));
        data.add(new Baidai("无拉丝，有粘液","浑浊、粘稠粘液，已经排完卵了",false));
        return data;
    }

    private void initOldSelected(){
        for(int i=0;i<data.size();i++){
            if(data.get(i).title.equals(old)){
                data.get(i).checked = true;
                break;
            }
        }

    }
}
